import { api } from '@/request'
import { httpServer, LoginProps , FindUserByuserNameProps, CreateUserProps, FindUserByIdProps} from './api'

// 获取验证码
export const queryCaptcha = () => {
  return api.post({
    url:`/api/auth/captcha`
  }
 )
}


// 登录
export const login: httpServer<LoginProps> = ({username, password, captcha, actionType}) => {
  return api.post({
      url:`/api/auth/login`,
      data:{
        username, 
        password,
        captcha,
        actionType
      },
    })
}


// 根据用户名查是否有该用户
export const findUserByuserName : httpServer<FindUserByuserNameProps> = ({username}) => {
  return api.get({
    url:`/api/user/findUserByName/${username}`,
  })
}


// 新增用户
export const createUser: httpServer<CreateUserProps> = ({password, username, captcha, email}) => {
  return api.post({
    url: `/api/user/addUser`,
    data: {
      password, 
      username,
      captcha,
      email
    }
  })
}


// 根据id查用户信息
export const finduserById :httpServer<FindUserByIdProps> = ({id}) => {
  return api.get({
    url:`/api/user/getUserById/${id}`
  })
}